#include <pd_gpio.h>
#include <hd_led.h>
#include <hd_key.h>
#include "main.h"

extern void SystemClock_Config(void);

Light *led_init(GPIO_TypeDef *GPIOx, uint32_t Pin) {
    GPIO *gpio = GPIOBuilder.build(GPIOx, Pin);
    Light *led = LEDBuilder.build(gpio);
    led->init(led);
    return led;
}

int main(void) {
    SystemClock_Config();

    uint8_t keyNum;

    Light *red_led = led_init(GPIOB, LL_GPIO_PIN_1);
    Light *green_led = led_init(GPIOB, LL_GPIO_PIN_0);
    Light *blue_led = led_init(GPIOB, LL_GPIO_PIN_3);

    // PB6/PF4/BOOT0 share one pin
    GPIO *keyGPIO = GPIOBuilder.build(GPIOF, LL_GPIO_PIN_4);
    keyGPIO->Pull = LL_GPIO_PULL_DOWN;
    Key *key = KeyBuilder.build(keyGPIO);
    key->init(key);

    while (1) {
        keyNum = key->getKeyNum(key);
        if (keyNum == 1) {
            red_led->turn(red_led);
            green_led->turn(green_led);
            blue_led->turn(blue_led);
        }
    }

}

